package servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.jusu.dao.UserDaoImpl;
import com.jusu.entity.User;
import com.jusu.biz.IUserBiz;
import com.jusu.biz.UserBizImpl;
import com.jusu.dao.IUserDao;

/**
 * Servlet implementation class UserServlet
 */
public class DoUser extends HttpServlet {
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		HttpSession session = request.getSession();
		String choise = request.getParameter("choise");
		response.setContentType("text/html;charset=UTF-8");
		PrintWriter out = response.getWriter();
		IUserBiz userBiz = new UserBizImpl();
		
		//System.out.println(choise);
		if("login".equals(choise)){
			String userName = request.getParameter("username");
			String userPwd = request.getParameter("userpwd");
			//int flag=userDao.findUserName(userName);
			User user = userBiz.login(new User(userName,userPwd));
			if(user != null){
				session.setAttribute("user", user);
				//System.out.println(user);
				response.sendRedirect("index.jsp");
			}else {
				System.out.println(user);
				response.sendRedirect("login.jsp");
			}
		}
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
